package com.ssh.web.common;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport {
	private static final long serialVersionUID = 7808362863961661905L;

	protected static HttpServletRequest request;
	protected static HttpServletResponse response;

	public static final int PAGESIZE = 100;
	public int pageNo = 1;
	public int currentPage = 1;
	public int totalPage = 1;
	public int totalRecordCount = 0;

	static {
		request = getRequest();
		response = getResponse();
	}

	public static HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}
	public static HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}
	public static void setAttribute(String key, Object o) {
		getRequest().setAttribute(key, o);
	}
	public void setPageInfo(List list, int pagesize) {
		totalRecordCount = list.size();
		totalPage = totalRecordCount % pagesize == 0 ? (totalRecordCount / pagesize) : (totalRecordCount / pagesize + 1);

		setAttribute("totalRecordCount",totalRecordCount);
		setAttribute("totalPage",totalPage);

		setAttribute("pagesize",pagesize);

	}
	public int getPageNo() {
		pageNo = getRequest().getParameter("pageNo") == null ? 1 :  Integer.valueOf(getRequest().getParameter("pageNo"));
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getTotalRecordCount() {
		return totalRecordCount;
	}
	public void setTotalRecordCount(int totalRecordCount) {
		this.totalRecordCount = totalRecordCount;
	}
	public static void setRequest(HttpServletRequest request) {
		BaseAction.request = request;
	}
	public static void setResponse(HttpServletResponse response) {
		BaseAction.response = response;
	}


}
